package org.springblade.modules.notice.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.modules.notice.enums.placeholder.AbarbeitungVariable;
import org.springblade.modules.notice.enums.placeholder.RepairVariable;
import org.springblade.modules.notice.enums.placeholder.RescueVariable;
import org.springblade.modules.notice.enums.placeholder.VariableEnum;
import org.springblade.modules.notice.vo.CommonEnumInfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @Author ysq
 * @Date 2024/11/20
 * @Description 消息模板-所属业务类型枚举
 */
@Getter
@AllArgsConstructor
public enum BusinessType {

	MAINTENANCE(1, "保养", null),

	REPAIR(2, "维修", RepairVariable.class),

	RESCUE(3, "救援", RescueVariable.class),

	PART(4, "配件", null),

	AFFAIR(5, "事务", null),

	CHECK(6, "质检", null),

	RATING(7, "评分", null),

	ATTENDANCE(8, "考勤", null),

	CERTIFICATE(9, "证件", null),

	CONTRACT(10, "合同", null),

	PROJECT(11, "项目", null),

	ABARBEITUNG(12, "整改", AbarbeitungVariable.class),

	;

	/**
	 * 编码值
	 */
	private final Integer code;

	/**
	 * 描述
	 */
	private final String desc;

	/**
	 * 业务对应变量枚举类
	 */
	private final Class<? extends VariableEnum> variableEnumClass;

	/**
	 * 获取可选列表
	 */
	public static List<CommonEnumInfo> getSelectList() {
		List<CommonEnumInfo> list = new ArrayList<>(16);
		for (BusinessType value : values()) {
			list.add(new CommonEnumInfo(value.getCode(), value.getDesc()));
		}
		return list;
	}

	/**
	 * 通过code获取class
	 *
	 * @param code
	 * @return
	 */
	public static Class<? extends VariableEnum> getVariableEnumClassByCode(Integer code) {
		return Arrays.stream(values()).filter(businessType -> Objects.equals(code, businessType.getCode()))
			.map(BusinessType::getVariableEnumClass)
			.filter(Objects::nonNull)
			.findFirst().orElse(null);
	}

	/**
	 * 通过code获取描述
	 * @param code
	 * @return
	 */
	public static String getDesc(Integer code) {
		return Arrays.stream(values()).filter(businessType -> Objects.equals(code, businessType.getCode()))
			.map(BusinessType::getDesc)
			.findFirst().orElse(null);
	}
}
